//
//  TipSuperView.m
//  BalanceCar
//
//  Created by 郑信鸿 on 17/6/28.
//  Copyright © 2017年 郑信鸿. All rights reserved.
//

#import "TipSuperView.h"

@interface TipSuperView ()

@property(nonatomic, weak)BaseTipView *tipView;

@property(nonatomic, assign)CGFloat verticalY;

@end

@implementation TipSuperView

+ (instancetype)tipSuperViewWithTipView:(BaseTipView *)tipView verticalY:(CGFloat)verticalY{
    TipSuperView *tipSuperView = [[TipSuperView alloc] initWithTipView:tipView verticalY:verticalY];
    
    return tipSuperView;
}


- (instancetype)initWithTipView:(BaseTipView *)tipView verticalY:(CGFloat)verticalY{
    
    if (self = [super init]) {
        self.frame = CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight);
        self.backgroundColor = RGBAColor(0, 0, 0, 0.4);
        self.tipView = tipView;
        self.verticalY = verticalY;
        [self addSubview:tipView];
        [self configFrame];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideView)];
        [self addGestureRecognizer:tap];
    }
    return self;
}

- (void)configFrame{
    
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_offset(0);
        make.top.mas_offset(self.verticalY);
        make.width.mas_offset(self.tipView.tip_width);
        make.height.mas_offset(self.tipView.tip_height);
        
    }];
    
}



- (void)showInView{
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
}

- (void)replaceTipView:(BaseTipView *)tipView{
   // BaseTipView *tempView = self.tipView;
    [self.tipView removeFromSuperview];
    self.tipView = tipView;
    [self addSubview:self.tipView];
    [self configFrame];
}


- (void)hideView{
    [self removeFromSuperview];
}


@end
